package entity.lemming;

import entity.Entity;
import entity.Sprite;
import level.*;

/**
 * A representation of a genaric Lemming entity
 * 
 * @author Neil Cowzer
 */
public abstract class Lemming extends Sprite {
	/** The status of the lemmings health.*/
	protected boolean alive;
	
	/** The energy level of the lemming.*/
	protected int energy;
	/*@ invariant 0 <= energy &&
					   energy <= 100;
	@*/
	
	/** The current speed of the lemming in the x-plane. */
	protected int speed_X;

	
	/** The current speed of the lemming in the y-plane. */
	protected int speed_Y;

	
	/**
	 * Create a new Lemming.
	 * 
	 * @param level The level which the Lemming exist in.
	 * @param ref The sprite which should be displayed.
	 * @param x The x-coordinate of the Lemming.
	 * @param y The y-coordinate of the Lemming.
	 */
	/*@ requires ref != null && 0 <= x && 0 <= y && level != null;
	   	assignable level;
	   	ensures true;
	 */
	public Lemming(String ref, int x,int y) {
		super(ref, 5, x, y);
		// bring the lemming to life
		alive = true;
	}
	
	/** Request that this lemming perform the appropiate action/movement. */
	public abstract void move();
	
	/** Kill the current lemming */
	//@ ensures alive == false;
	public void kill(){
		alive = false;
	}
	
	/** Reverse a Lemmings direction */
	/*@ ensures speed_X == 0 - \old(speed_X) &&
	 			speed_Y == 0 - \old(speed_Y);
	@*/
	public void turnAround(){
		speed_X = -(speed_X);
		speed_Y = -(speed_Y);
	}
	
	/**
	 * Check if this Lemming should enter free-fall.
	 * 
	 * @return True if the Lemming should free-fall
	 */
	public boolean fall(){
		// if there is no ground beneath the lemming enter free-fall
		// else
		return false;
	}
	
	/**
	 * Check if the Lemming is alive
	 * 
	 * @return True if Lemming is alive
	 */
	public /*@ pure @*/ boolean isAlive(){
		return alive;
	}
	
	/**
	 * Retrieve the Lemmings speed in the x-plane
	 * 
	 * @return the integer value of the speed
	 */
	public /*@ pure @*/ int energy(){
		return energy;
	}
	
	/**
	 * Retrieve the Lemmings speed in the x-plane
	 * 
	 * @return the integer value of the speed
	 */
	public /*@ pure @*/ int getSpeed_X(){
		return speed_X;
	}
	
	/**
	 * Retrieve the Lemmings speed in the y-plane
	 * 
	 * @return the integer value of the speed
	 */
	public /*@ pure @*/ int getSpeed_Y(){
		return speed_Y;
	}
	
	/**
	 * Check to see if a Lemming collides with another entity
	 * 
	 * @param other another entity eg. terrain, blocker.
	 * @return True if Lemming collides with another
	 */
	public abstract boolean collision(Entity other);
}
